<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 数组的平方 -->
    <script>
      var sortedSquares = function (nums) {
        let i = 0
        let j = nums.length - 1
        let newnums = []
        let k = nums.length - 1
        for (let m = 0; m < nums.length; m++) {
          if (nums[i] * nums[i] < nums[j] * nums[j]) {
            newnums[k--] = nums[j] * nums[j]
            j--
          }
          if (nums[i] * nums[i] >= nums[j] * nums[j]) {
            newnums[k--] = nums[i] * nums[i]
            i++
          }
        }
        return newnums
      }
      console.log(sortedSquares([-4, -1, 0, 3, 10]))
    </script>
  </body>
</html>
